import {fireEvent as dtlFireEvent} from '@testing-library/dom'

const fireEvent = (...args) => dtlFireEvent(...args)

Object.keys(dtlFireEvent).forEach(key => {
  fireEvent[key] = (...args) => dtlFireEvent[key](...args)
})

// 添加 Inula 特定的事件处理
const mouseEnter = fireEvent.mouseEnter
const mouseLeave = fireEvent.mouseLeave
fireEvent.mouseEnter = (...args) => {
  mouseEnter(...args)
  return fireEvent.mouseOver(...args)
}
fireEvent.mouseLeave = (...args) => {
  mouseLeave(...args)
  return fireEvent.mouseOut(...args)
}

const select = fireEvent.select
fireEvent.select = (node, init) => {
  select(node, init)
  node.focus()
  fireEvent.keyUp(node, init)
}

const blur = fireEvent.blur
const focus = fireEvent.focus
fireEvent.blur = (...args) => {
  fireEvent.focusOut(...args)
  return blur(...args)
}
fireEvent.focus = (...args) => {
  fireEvent.focusIn(...args)
  return focus(...args)
}

export {fireEvent}